package com.hd123.rumba.qt.html;

import java.io.FileOutputStream;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Vector;

import com.hd123.rumba.qt.def.SQLColumn;
import com.hd123.rumba.qt.def.SQLColumnList;
import com.hd123.rumba.sql.JdbcRow;

public class TestPrintTable {

  public static void main(String[] args) throws Exception {
    PrintTable g = new PrintTable();

    Object[][] raw = new Object[][] {
        {
            "时间", "门店", "商品", "状态", "数量", "定货", "定货信息", "金额" },
        {
            "2个月以上", "久盛店", "00000179", "正常", new Integer(1), "否", null, new BigDecimal(800.00) },
        {
            "2个月以上", "久盛店", "00000323", "正常", new Integer(1), "否", null, new BigDecimal(500.00) },
        {
            "2个月以上", "真北_红星", "00000340", "正常", new Integer(1), "否", "23", new BigDecimal(500.00) },
        {
            "3个月以上", "澳门_月星", "00000177", "正常", new Integer(1), "否", "", new BigDecimal(500.00) },
        {
            "3个月以上", "澳门_月星", "00000179", "正常", new Integer(1), "否", "", new BigDecimal(800) },
        {
            "3个月以上", "澳门_月星", "00000229", "正常", new Integer(1), "否", "", new BigDecimal(500) },
        {
            "3个月以上", "澳门_月星", "00000249", "正常", new Integer(1), "否", "", new BigDecimal(800) },
        {
            "3个月以上", "澳门_月星", "00000340", "正常", new Integer(1), "否", "", new BigDecimal(500) },
        {
            "3个月以上", "真北_红星", "00000229", "正常", new Integer(1), "否", "", new BigDecimal(500) },
        {
            "3个月以上", "真北_红星", "00000249", "正常", new Integer(1), "否", "", new BigDecimal(800) } };
    SQLColumnList columns = new SQLColumnList();
    for (int i = 0; i < raw[0].length; ++i) {
      SQLColumn column = new SQLColumn();
      columns.add(column);
      column.setTitle((String) raw[0][i]);
    }
    columns.get(0).setGroupIndex(0);
    columns.get(1).setGroupIndex(1);
    columns.get(4).setGAggregation("SUM");
    columns.get(7).setGAggregation("SUM");
    g.setVisibleColumns(columns);

    Vector names = new Vector();
    for (int i = 0; i < raw[0].length; ++i)
      names.add("A" + i);
    g.setNames(names);

    Vector data = new Vector();
    for (int i = 1; i < raw.length; ++i) {
      JdbcRow row = new JdbcRow();
      data.add(row);
      for (int j = 0; j < raw[i].length; ++j) {
        row.put(names.get(j), raw[i][j]);
      }
    }
    g.setResults(data);

    g.setSummary(data);

    PrintStream out = new PrintStream(new FileOutputStream("c:/temp/g.htm"));
    g.setOut(out);
    g.print();
    out.close();
    System.out.println("file generated at " + new Date());
  }
}
